package com.foo.idcardidentify.dao.impl;

import com.foo.idcardidentify.dao.IIdcardDao;
import com.foo.idcardidentify.entity.IdcardEntity;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

@Repository
public class IdcardDaoImpl implements IIdcardDao {
    @PersistenceContext
    private EntityManager em;


    @Override
    public int count() {
        Query query = em.createQuery("select count(id) from IdcardEntity");
        return query.executeUpdate();
    }

    @Override
    public void save(IdcardEntity entity) {
        em.persist(entity);
    }

    @Override
    public void update(IdcardEntity entity) {
        em.merge(entity);
    }

    @Override
    public List<IdcardEntity> findAll() {
        return em.createQuery("from IdcardEntity", IdcardEntity.class).getResultList();
    }

}
